package com.tjtt.tdm.system.dao.impl;
import java.io.IOException;
import java.util.Map;

import com.tjtt.tdm.base.HibernateEntityDAO;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.exception.ServiceException;
import com.tjtt.tdm.system.bean.SysCerify;
import com.tjtt.tdm.system.dao.CerifyDao;

public class CerifyDaoImpl extends HibernateEntityDAO<SysCerify> implements CerifyDao {
	/**
	 * 查询所有证书
	 * @throws Exception
	 */
	public PageResult querycerifyInfo(Map<String, String> filterMap,String userid) {
		StringBuffer queryString = new StringBuffer();
		queryString.append("select t.id,t.cerify_no,t.cerify_name,u.USERNAME,t.cerify_date,t.cerify_type,t.cerify_overdate,t.cerify_desc,t.CERIFY_PAST_TIME from sys_cerify t left join SYS_USERS u on t.cerify_user=u.USERID where t.cerify_user ="+userid+" ");
		StringBuffer countString = new StringBuffer();
		countString.append("select count(*) from (select t.id,t.cerify_no,t.cerify_name,u.USERNAME,t.cerify_date,t.cerify_type,t.cerify_overdate,t.cerify_desc,t.CERIFY_PAST_TIME from sys_cerify t left join SYS_USERS u on t.cerify_user=u.USERID where t.cerify_user ="+userid+" ) ");
		if (filterMap != null && !filterMap.isEmpty()) {
			String sidx = (String)filterMap.get("sidx");
			String sord = (String)filterMap.get("sord");
			queryString.append(" order by " + sidx + " " + sord );
		}
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);	
	}

	/**
	 * 删除证书
	 * @throws IOException
	 * @throws ServiceException void
	 * @author 
	 * @date
	 */
	public void deleteCerity(SysCerify sysCerify) {
		this.getHibernateTemplate().delete(sysCerify);
	}

	@Override
	public SysCerify findCerityById(long id) {
		SysCerify sysCerify = (SysCerify) super.getHibernateTemplate().get(SysCerify.class ,id);
		return sysCerify;
	}

	@Override
	public SysCerify checkOneCerifyById(Long id) {
		SysCerify sysCerify = (SysCerify) super.getHibernateTemplate().get(SysCerify.class ,id);
		return sysCerify;
	}
}
